package com.ctrip.ec.biz.dao.goods;
import com.ctrip.ec.biz.entity.goods.GoodsImageEntity;
import com.ctrip.ec.dal.DaoBase;
import com.ctrip.ec.biz.entity.goods.GoodsRebateEntity;
import com.ctrip.ec.dal.DbAccess;
import org.springframework.stereotype.Service;

import java.sql.SQLException;
import java.util.List;

@Service
public class GoodsRebateDao extends DaoBase<GoodsRebateEntity> {
    public GoodsRebateDao() {
        super(GoodsRebateEntity.class);
    }
    public GoodsRebateDao(DbAccess db) {
        super(GoodsRebateEntity.class,db);
    }

    public List<GoodsRebateEntity> listByGoodsId(Long id) throws SQLException {
        String sql = "select * from " + this.getTableName() + " where goods_id = ?";
        List<GoodsRebateEntity> list = this.db.query(GoodsRebateEntity.class,sql,id);
        return list;
    }

    public GoodsRebateEntity entity(Long goodsId, Integer memberLevel) throws SQLException {
        String sql = "select * from " + this.getTableName() + " where goods_id=? and vip=?";
        List<GoodsRebateEntity> list = this.db.query(GoodsRebateEntity.class,sql,goodsId,memberLevel);
        if(list.size()>0){
            return list.get(0);
        }else{
            return null;
        }
    }
}
